package org.netwia.networks.nodes;

import java.util.Map;

import org.apache.commons.lang3.builder.ToStringBuilder;
import org.netwia.networks.Node;

/**
 * Implementation of node which summarizes the double numbers.
 * 
 * @author radek.hecl
 *
 */
public class DoubleSumNode implements Node<Double> {

    /**
     * Builder object.
     */
    public static class Builder {

        /**
         * Builds the result object.
         * 
         * @return created object
         */
        public DoubleSumNode build() {
            return new DoubleSumNode(this);
        }
    }

    /**
     * Creates new instance.
     * 
     * @param builder builder object
     */
    public DoubleSumNode(Builder builder) {
        guardInvariants();
    }

    /**
     * Guards this object to be consistent. Throws exception if this is not the case.
     */
    private void guardInvariants() {
    }

    @Override
    public Double process(Map<String, Double> inputs) {
        double res = 0;
        for (String key : inputs.keySet()) {
            res = res + inputs.get(key); 
        }
        return res;
    }
    
    @Override
    public String toString() {
        return ToStringBuilder.reflectionToString(this);
    }

}
